<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html 
     PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <title>Class: Origami::Encryption::Standard::Dictionary</title>
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  <meta http-equiv="Content-Script-Type" content="text/javascript" />
  <link rel="stylesheet" href="../../../.././rdoc-style.css" type="text/css" media="screen" />
  <script type="text/javascript">
  // <![CDATA[

  function popupCode( url ) {
    window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
  }

  function toggleCode( id ) {
    if ( document.getElementById )
      elem = document.getElementById( id );
    else if ( document.all )
      elem = eval( "document.all." + id );
    else
      return false;

    elemStyle = elem.style;
    
    if ( elemStyle.display != "block" ) {
      elemStyle.display = "block"
    } else {
      elemStyle.display = "none"
    }

    return true;
  }
  
  // Make codeblocks hidden by default
  document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
  
  // ]]>
  </script>

</head>
<body>



    <div id="classHeader">
        <table class="header-table">
        <tr class="top-aligned-row">
          <td><strong>Class</strong></td>
          <td class="class-name-in-header">Origami::Encryption::Standard::Dictionary</td>
        </tr>
        <tr class="top-aligned-row">
            <td><strong>In:</strong></td>
            <td>
                <a href="../../../../files/origami/encryption_rb.html">
                origami/encryption.rb
                </a>
        <br />
            </td>
        </tr>

        <tr class="top-aligned-row">
            <td><strong>Parent:</strong></td>
            <td>
                EncryptionDictionary
            </td>
        </tr>
        </table>
    </div>
  <!-- banner header -->

  <div id="bodyContent">



  <div id="contextContent">

    <div id="description">
      <p>
Class defining a standard encryption dictionary.
</p>

    </div>


   </div>

    <div id="method-list">
      <h3 class="section-bar">Methods</h3>

      <div class="name-list">
      <a href="#M000256">compute_encryption_key</a>&nbsp;&nbsp;
      <a href="#M000260">is_owner_password?</a>&nbsp;&nbsp;
      <a href="#M000259">is_user_password?</a>&nbsp;&nbsp;
      <a href="#M000257">set_owner_password</a>&nbsp;&nbsp;
      <a href="#M000258">set_user_password</a>&nbsp;&nbsp;
      </div>
    </div>

  </div>


    <!-- if includes -->

    <div id="section">


    <div id="constants-list">
      <h3 class="section-bar">Constants</h3>

      <div class="name-list">
        <table summary="Constants">
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">O</td>
          <td>=</td>
          <td class="context-item-value">owner_key</td>
        </tr>
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">U</td>
          <td>=</td>
          <td class="context-item-value">compute_user_password(userpassword, fileid)</td>
        </tr>
        </table>
      </div>
    </div>



      


    <!-- if method_list -->
    <div id="methods">
      <h3 class="section-bar">Public Instance methods</h3>

      <div id="method-M000256" class="method-detail">
        <a name="M000256"></a>

        <div class="method-heading">
          <a href="#M000256" class="method-signature">
          <span class="method-name">compute_encryption_key</span><span class="method-args">(password, fileid)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Computes the key that will be used to encrypt/decrypt the document.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000256-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000256-source">
<pre>
      <span class="ruby-comment cmt"># File origami/encryption.rb, line 993</span>
 993:         <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">compute_encryption_key</span>(<span class="ruby-identifier">password</span>, <span class="ruby-identifier">fileid</span>)
 994:           
 995:           <span class="ruby-identifier">padded</span> = <span class="ruby-identifier">pad_password</span>(<span class="ruby-identifier">password</span>)
 996: 
 997:           <span class="ruby-identifier">padded</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-constant">O</span>
 998:           <span class="ruby-identifier">padded</span> <span class="ruby-operator">&lt;&lt;</span> [ <span class="ruby-keyword kw">self</span>.<span class="ruby-constant">P</span> ].<span class="ruby-identifier">pack</span>(<span class="ruby-value str">&quot;i&quot;</span>)
 999:           
1000:           <span class="ruby-identifier">padded</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">fileid</span>
1001:           
1002:           <span class="ruby-identifier">encrypt_metadata</span> = <span class="ruby-keyword kw">self</span>.<span class="ruby-constant">EncryptMetadata</span> <span class="ruby-operator">!=</span> <span class="ruby-keyword kw">false</span>
1003:           <span class="ruby-identifier">padded</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-value str">&quot;\xFF\xFF\xFF\xFF&quot;</span> <span class="ruby-keyword kw">if</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-constant">R</span> <span class="ruby-operator">&gt;=</span> <span class="ruby-value">4</span> <span class="ruby-keyword kw">and</span> <span class="ruby-keyword kw">not</span> <span class="ruby-identifier">encrypt_metadata</span>
1004: 
1005:           <span class="ruby-identifier">key</span> = <span class="ruby-constant">Digest</span><span class="ruby-operator">::</span><span class="ruby-constant">MD5</span>.<span class="ruby-identifier">digest</span>(<span class="ruby-identifier">padded</span>)
1006: 
1007:           <span class="ruby-value">50</span>.<span class="ruby-identifier">times</span> { <span class="ruby-identifier">key</span> = <span class="ruby-constant">Digest</span><span class="ruby-operator">::</span><span class="ruby-constant">MD5</span>.<span class="ruby-identifier">digest</span>(<span class="ruby-identifier">key</span>[<span class="ruby-value">0</span>, <span class="ruby-keyword kw">self</span>.<span class="ruby-constant">Length</span> <span class="ruby-operator">/</span> <span class="ruby-value">8</span>]) } <span class="ruby-keyword kw">if</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-constant">R</span> <span class="ruby-operator">&gt;=</span> <span class="ruby-value">3</span>
1008: 
1009:           <span class="ruby-keyword kw">if</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-constant">R</span> <span class="ruby-operator">==</span> <span class="ruby-value">2</span>
1010:             <span class="ruby-identifier">key</span>[<span class="ruby-value">0</span>, <span class="ruby-value">5</span>]
1011:           <span class="ruby-keyword kw">elsif</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-constant">R</span> <span class="ruby-operator">&gt;=</span> <span class="ruby-value">3</span>
1012:             <span class="ruby-identifier">key</span>[<span class="ruby-value">0</span>, <span class="ruby-keyword kw">self</span>.<span class="ruby-constant">Length</span> <span class="ruby-operator">/</span> <span class="ruby-value">8</span>]
1013:           <span class="ruby-keyword kw">end</span>
1014:            
1015:         <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000260" class="method-detail">
        <a name="M000260"></a>

        <div class="method-heading">
          <a href="#M000260" class="method-signature">
          <span class="method-name">is_owner_password?</span><span class="method-args">(pass, fileid)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Checks owner password.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000260-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000260-source">
<pre>
      <span class="ruby-comment cmt"># File origami/encryption.rb, line 1055</span>
1055:         <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">is_owner_password?</span>(<span class="ruby-identifier">pass</span>, <span class="ruby-identifier">fileid</span>)
1056:         
1057:           <span class="ruby-identifier">key</span> = <span class="ruby-identifier">compute_owner_encryption_key</span>(<span class="ruby-identifier">pass</span>)
1058: 
1059:           <span class="ruby-keyword kw">if</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-constant">R</span> <span class="ruby-operator">==</span> <span class="ruby-value">2</span>
1060:             <span class="ruby-identifier">user_password</span> = <span class="ruby-constant">ARC4</span>.<span class="ruby-identifier">decrypt</span>(<span class="ruby-identifier">key</span>, <span class="ruby-keyword kw">self</span>.<span class="ruby-constant">O</span>)
1061:           <span class="ruby-keyword kw">elsif</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-constant">R</span> <span class="ruby-operator">&gt;=</span> <span class="ruby-value">3</span>
1062:             <span class="ruby-identifier">user_password</span> = <span class="ruby-constant">ARC4</span>.<span class="ruby-identifier">decrypt</span>(<span class="ruby-identifier">xor</span>(<span class="ruby-identifier">key</span>, <span class="ruby-value">19</span>), <span class="ruby-keyword kw">self</span>.<span class="ruby-constant">O</span>)
1063:             <span class="ruby-value">19</span>.<span class="ruby-identifier">times</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">i</span><span class="ruby-operator">|</span> <span class="ruby-identifier">user_password</span> = <span class="ruby-constant">ARC4</span>.<span class="ruby-identifier">decrypt</span>(<span class="ruby-identifier">xor</span>(<span class="ruby-identifier">key</span>, <span class="ruby-value">18</span><span class="ruby-operator">-</span><span class="ruby-identifier">i</span>), <span class="ruby-identifier">user_password</span>) }
1064:           <span class="ruby-keyword kw">end</span>
1065:           
1066:           <span class="ruby-identifier">is_user_password?</span>(<span class="ruby-identifier">user_password</span>, <span class="ruby-identifier">fileid</span>)
1067:         <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000259" class="method-detail">
        <a name="M000259"></a>

        <div class="method-heading">
          <a href="#M000259" class="method-signature">
          <span class="method-name">is_user_password?</span><span class="method-args">(pass, fileid)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Checks user password.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000259-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000259-source">
<pre>
      <span class="ruby-comment cmt"># File origami/encryption.rb, line 1042</span>
1042:         <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">is_user_password?</span>(<span class="ruby-identifier">pass</span>, <span class="ruby-identifier">fileid</span>)
1043:           
1044:           <span class="ruby-keyword kw">if</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-constant">R</span> <span class="ruby-operator">==</span> <span class="ruby-value">2</span> 
1045:             <span class="ruby-identifier">compute_user_password</span>(<span class="ruby-identifier">pass</span>, <span class="ruby-identifier">fileid</span>) <span class="ruby-operator">==</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-constant">U</span>
1046:           <span class="ruby-keyword kw">elsif</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-constant">R</span> <span class="ruby-operator">&gt;=</span> <span class="ruby-value">3</span>
1047:             <span class="ruby-identifier">compute_user_password</span>(<span class="ruby-identifier">pass</span>, <span class="ruby-identifier">fileid</span>)[<span class="ruby-value">0</span>, <span class="ruby-value">16</span>] <span class="ruby-operator">==</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-constant">U</span>[<span class="ruby-value">0</span>, <span class="ruby-value">16</span>]
1048:           <span class="ruby-keyword kw">end</span>
1049:           
1050:         <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000257" class="method-detail">
        <a name="M000257"></a>

        <div class="method-heading">
          <a href="#M000257" class="method-signature">
          <span class="method-name">set_owner_password</span><span class="method-args">(userpassword, ownerpassword = nil)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Set owner password.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000257-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000257-source">
<pre>
      <span class="ruby-comment cmt"># File origami/encryption.rb, line 1020</span>
1020:         <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">set_owner_password</span>(<span class="ruby-identifier">userpassword</span>, <span class="ruby-identifier">ownerpassword</span> = <span class="ruby-keyword kw">nil</span>)
1021:           
1022:           <span class="ruby-identifier">key</span> = <span class="ruby-identifier">compute_owner_encryption_key</span>(<span class="ruby-identifier">userpassword</span>, <span class="ruby-identifier">ownerpassword</span>)
1023:           <span class="ruby-identifier">upadded</span> = <span class="ruby-identifier">pad_password</span>(<span class="ruby-identifier">userpassword</span>)
1024:           
1025:           <span class="ruby-identifier">owner_key</span> = <span class="ruby-constant">ARC4</span>.<span class="ruby-identifier">encrypt</span>(<span class="ruby-identifier">key</span>, <span class="ruby-identifier">upadded</span>)
1026:           <span class="ruby-value">19</span>.<span class="ruby-identifier">times</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">i</span><span class="ruby-operator">|</span> <span class="ruby-identifier">owner_key</span> = <span class="ruby-constant">ARC4</span>.<span class="ruby-identifier">encrypt</span>(<span class="ruby-identifier">xor</span>(<span class="ruby-identifier">key</span>,<span class="ruby-identifier">i</span><span class="ruby-operator">+</span><span class="ruby-value">1</span>), <span class="ruby-identifier">owner_key</span>) } <span class="ruby-keyword kw">if</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-constant">R</span> <span class="ruby-operator">&gt;=</span> <span class="ruby-value">3</span>
1027:           
1028:           <span class="ruby-keyword kw">self</span>.<span class="ruby-constant">O</span> = <span class="ruby-identifier">owner_key</span>
1029:         <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000258" class="method-detail">
        <a name="M000258"></a>

        <div class="method-heading">
          <a href="#M000258" class="method-signature">
          <span class="method-name">set_user_password</span><span class="method-args">(userpassword, fileid = nil)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Set user password.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000258-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000258-source">
<pre>
      <span class="ruby-comment cmt"># File origami/encryption.rb, line 1034</span>
1034:         <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">set_user_password</span>(<span class="ruby-identifier">userpassword</span>, <span class="ruby-identifier">fileid</span> = <span class="ruby-keyword kw">nil</span>)
1035:           
1036:           <span class="ruby-keyword kw">self</span>.<span class="ruby-constant">U</span> = <span class="ruby-identifier">compute_user_password</span>(<span class="ruby-identifier">userpassword</span>, <span class="ruby-identifier">fileid</span>)
1037:         <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>


    </div>


  </div>


<div id="validator-badges">
  <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
</div>

</body>
</html>